package monsmon.game.draw;

import java.util.*;
import monsmon.term.Surface;
import monsmon.util.Util;
import monsmon.util.TermUtil;
import monsmon.util.Triple;
import monsmon.util.Pair;

public class MsgQueue{
	
	//Max number of msgs in the buffer
	public static final int BUFF_LEN = 1000;

	private LinkedList<String> msgs = new LinkedList<String>();	
	

	public void add_msg(String s){
		s = s.replace("\n", "");
		if(!msgs.offerFirst(s)){
			System.out.println("Something went wrong adding to the"
					+ " que");
		}
		if(msgs.size() >= BUFF_LEN){
			msgs.pollLast();
		}
	}

	public void render(Surface surf){
		int len = surf.get_w();
		int dph = surf.get_h();

		int y = dph-2;
		for(String cs : msgs){
			int bk = Util.sf_len(cs) / len + 1;
			y -= bk;
			TermUtil.swritef(surf, 0, y, cs, true);
			if(y <= 0){
				break;
			}
		}
	}

}
